/* 关联订单
 * @Author: Setsuna
 * @Email: setsuna.xyz@qq.com
 * @FilePath: \src\pages\QuotaManage\StockCheck\QuatoDetail\component\LinkOrders.tsx
 * @Date: 2023-04-27 20:43:58
 * @LastEditTime: 2023-04-27 20:44:03
 * @LastEditors: Setsuna
 */
import React from 'react'
import { http } from '@/lib'
import { Table } from 'antd'
import apis  from '@/apis/AboutQuota'
interface IProps {
  orderParams?: any
}
interface IState {
  dataSource?: any
  page?: number
  total?: number
  size?: number
  loading?: boolean
}
export default class LinkDetail extends React.Component<IProps, IState> {
  private record = this.props.orderParams
  constructor(props: IProps, state: IState) {
    super(props)
    this.state = {
      page: 1,
      size: 10,
      total: 0,
      dataSource: [],
      loading: false,
    }
  }
  componentDidMount() {
    this.getOrderTableData()
  }
  render() {
    return (
      <>
        <Table
          rowKey="orderNum"
          columns={[
            { title: '序号', dataIndex: 'id', render: (text, record, index) => index + 1 },
            { title: '订单编号', dataIndex: 'number' },
            { title: '订单数量', dataIndex: 'amount' },
            {
              title: '下单时间',
              dataIndex: 'planDeliveryDate',
            },
          ]}
          dataSource={this.state.dataSource}
          onChange={this.handleChangePage}
          loading={this.state.loading}
          pagination={{
            current: this.state.page,
            pageSize: this.state.size,
            total: this.state.total,
            showQuickJumper: true,
            showSizeChanger: true,
            pageSizeOptions: ['10', '20', '30', '40'],
            showTotal: (total, range) => `共${total}项，当前${range[0]}-${range[1]}项`,
          }}
        />
      </>
    )
  }

  private handleChangePage = pagination => {
    const { current: page, pageSize: size } = pagination
    this.setState({ page, size }, () => {
      this.getOrderTableData()
    })
  }

  private getOrderTableData = async () => {
    this.setState({ loading: true })
    try {
      let list: any = await http.post(apis.getDealerOrderMaterialByPage, {
        page: this.state.page,
        size: this.state.size,
        ...this.record,
      })
      const dataSource = list.data?.content

      this.setState({
        dataSource,
        page: list.data.number,
        size: list.data.size,
        total: list.data.totalElements,
        loading: false,
      })
    } catch (error) {
      this.setState({
        loading: false,
      })
    }
  }
}
